package com.yidu.ReportManagement.mapper;

import com.yidu.DatelessManagement.entity.NetWorth;
import com.yidu.ReportManagement.entity.FundPortfolioTable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 基金投资板块表mapper层
 * @author 任俊杰
 * @version 1.0
 * @date 2023/2/10
 */
@Mapper
public interface FundPortfolioTableMapper {
    /**
     * 证券板块查询方法
     * @param Date 时间
     * @param fundId 基金id
     * @param DateTwo 行情时间
     * @return
     */
    @Select("SELECT (p.plateId)plateId,(p.plateName)plateName,SUM((ss.quantity))quantity,SUM((ss.quantity * m.closingPrice))marketValue FROM (SELECT * FROM plate WHERE plateId!='000' )p" +
            " JOIN (SELECT * FROM SECURITY)se ON se.plateId=p.plateId" +
            " JOIN (SELECT * FROM securityStock WHERE DATE=#{Date} and fundId=#{fundId} )ss on ss.securityId=se.securityId" +
            " JOIN (SELECT * FROM marketData WHERE TIME=#{DateTwo})m on m.securityId=ss.securityId group by p.plateId,p.plateName")
    public List<FundPortfolioTable> selectFundPortfolioTable(String Date, String fundId, String DateTwo);

    /**
     * 资产净值查询方法
     * @param Date s时间
     * @param fundId 基金id
     * @return
     */
    @Select (" select capital from netWorth where projectName='资产净值' and fundId=#{fundId} and createTime=#{createTime}")
    public NetWorth selectValue(String Date, String fundId);
}
